package mop.gui.project;

import java.util.LinkedList;
import javax.swing.DefaultListModel;
import mop.gui.GUI;
import mop.model.project.ProjectInterface;
import mop.model.task.TaskInterface;

/**
 * ProjectDetailsDialog
 * 
 * @author  Laurens
 */
public class ProjectDetailsDialog extends javax.swing.JDialog 
{
    /**
     * Constructor.
     * 
     * @param   gui
     * @param   project (interface)
     */
    public ProjectDetailsDialog(GUI gui, ProjectInterface project)
    {
        super(gui.getMainWindow(), true);
        initComponents();
        
        setGui(gui);
        
        this.project = project;
        
        this.setTitle("Project: " + project.getDescription());
        this.txtDescription.setText(project.getDescription());
        
        this.loadTasks();
    }
    
    /***************************************************************************
     *                          GUI reference
     ***************************************************************************/
    
    private GUI gui;
    
    /**
     * Sets the GUI.
     * 
     * @param   gui
     * @post    gui is set.
     */
    private void setGui(GUI gui)
    {
        this.gui = gui;
    }
    
    /**
     * Returns the GUI reference.
     * 
     * @return  this.gui
     */
    public GUI getGui()
    {
        return this.gui;
    }
    
    /***************************************************************************
     *                          Selected project
     ***************************************************************************/
    
    private ProjectInterface project;
    
    /***************************************************************************
     *                          Dialog-specific functionality
     ***************************************************************************/
    
    /**
     * Loads tasks in listmodel.
     */
    private void loadTasks()
    {
        LinkedList<TaskInterface> tasks = (LinkedList<TaskInterface>) project.getTaskList();
        DefaultListModel model = new DefaultListModel();
        for(TaskInterface t : tasks)
            model.addElement(t.getId());
        this.listTasks.setModel(model);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lblProjectDetails = new javax.swing.JLabel();
        lblDescription = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtDescription = new javax.swing.JTextArea();
        btnClose = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        listTasks = new javax.swing.JList();
        lblAssignedTasks = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        lblProjectDetails.setFont(new java.awt.Font("Tahoma", 1, 12));
        lblProjectDetails.setText("Project Details");
        lblProjectDetails.setName("lblProjectDetails"); // NOI18N

        lblDescription.setText("Description");
        lblDescription.setName("lblDescription"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        txtDescription.setColumns(20);
        txtDescription.setRows(5);
        txtDescription.setName("txtDescription"); // NOI18N
        jScrollPane1.setViewportView(txtDescription);

        btnClose.setText("Close");
        btnClose.setName("btnClose"); // NOI18N
        btnClose.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCloseActionPerformed(evt);
            }
        });

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        listTasks.setName("listTasks"); // NOI18N
        jScrollPane2.setViewportView(listTasks);

        lblAssignedTasks.setText("Assigned Tasks");
        lblAssignedTasks.setName("lblAssignedTasks"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 312, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 312, Short.MAX_VALUE)
                    .addComponent(lblProjectDetails, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblDescription, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblAssignedTasks, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnClose, javax.swing.GroupLayout.DEFAULT_SIZE, 312, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblProjectDetails)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblDescription)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblAssignedTasks)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 193, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnClose)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

/**
 * Closes this dialog.
 * 
 * @param   evt
 */
private void btnCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCloseActionPerformed
    this.dispose();
}//GEN-LAST:event_btnCloseActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnClose;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel lblAssignedTasks;
    private javax.swing.JLabel lblDescription;
    private javax.swing.JLabel lblProjectDetails;
    private javax.swing.JList listTasks;
    private javax.swing.JTextArea txtDescription;
    // End of variables declaration//GEN-END:variables
}